#ifndef GUI_H
#define GUI_H

#include <QtGui>
#include <QSystemTrayIcon>
#include <vector>
#include "db/dbc.h"


class Gui : public QWidget
{
  Q_OBJECT

  private: // constants
    static const char UPDATE_OPER = 'U';
    static const char DELETE_OPER = 'D';
    static const char INSERT_OPER = 'I';

  public: // public fields

  private: // private fields
    QLayout *lay;
    QTextEdit *itxt;
    QPushButton *startBtn;
    QPushButton *stopBtn;
    QPushButton *restartBtn;
    QPushButton *confBtn;
    QPushButton *quitBtn;

    QSystemTrayIcon *tray;
    QMenu *trayMenu;
    QAction *startAction;
    QAction *stopAction;
    QAction *restartAction;
    QAction *quitAction;

    std::vector<QString> sqlString;
    QString configLocalDBConnection;
    QString configRemoteDBConnection;
    QString configRemoteDBEncoding;
    QString configSqlReplicTableName;
    QString configRequestDelay;
    int delay;

    DBConnect *localDBConnection;
    DBConnect *remoteDBConnection;

    QTimer *timer;

  public: // public methods
    Gui(QWidget *parent = 0);
    ~Gui();

  protected:
    void closeEvent(QCloseEvent *event);

  private: // private methods
    void vectorQString2char(char *array, std::vector<QString> v);
    void setEncoding(QString sqlConnectionType, QString sqlEncoding, std::vector<QString> &v);
    int vectorQStringSize(std::vector<QString> v);
    bool init();
    DBConnect * createDBConnection(QString initString);
    bool setReplicData(DBConnect *connection, std::vector<QString> &sqlString);
    void getReplicData(DBConnect *connection, QString tableName, std::vector<QString> &sqlString);
    void createActions();
    void createTrayIcon();

  private slots:
    void start();
    void stop();
    void restart();
    void configure();
    void dbOperation();
    void setIcon(int index);
    void iconActivated(QSystemTrayIcon::ActivationReason reason);
    bool event(QEvent *e);
};

#endif // GUI_H
